var e = require("../../../../@babel/runtime/helpers/slicedToArray"),
  t = require("../../../../@babel/runtime/helpers/regeneratorRuntime"),
  r = require("../../../../@babel/runtime/helpers/asyncToGenerator"),
  a = require("../../../../store/index"),
  n = require("../../../../utils/index"),
  s = n.helper.tabCommon,
  i = n.helper.listOperate,
  o = n.tools.common.getHeaderHeight;

function u() {
  return c.apply(this, arguments)
}

function c() {
  return (c = r(t().mark((function r() {
    var n, i, o, u, c, l, h, p, d, f, g, m;
    return t().wrap((function (t) {
      for (;;) switch (t.prev = t.next) {
        case 0:
          return n = a.store.getState().storage.userLocationCity, i = a.store.getState().storage.userLocation, o = s.getTabMode(), u = s.getStorageKey(), c = s.getFilterParamsInfo(u), l = c.type.value, h = c.sort, p = {
            page: this.page,
            page_size: 15,
            source: "XCX",
            addr: (null == n ? void 0 : n.id) || 1,
            mode: o || 1,
            type: 0,
            pattern: (null == h ? void 0 : h.id) || 0
          }, i && (d = i.split(","), f = e(d, 2), g = f[0], m = f[1], Object.assign(p, {
            longitude: g,
            latitude: m
          })), t.abrupt("return", (null != l && l.length && (p.type = l[0].id), p));
        case 3:
        case "end":
          return t.stop()
      }
    }), r, this)
  })))).apply(this, arguments)
}
Component({
  componentPage: {
    onPullDownRefresh: function () {
      this.onRefresh(1).finally((function () {
        wx.stopPullDownRefresh()
      }))
    },
    onReachBottom: function () {
      this.isTabRefresh || this.data.hasMore || this.data.noData || this.onRefresh(this.page + 1)
    }
  },
  properties: {},
  data: {
    firstLoaded: !1,
    calcHeight: "0px",
    list: [],
    loading: !1,
    noData: !1,
    hasMore: !1
  },
  methods: {
    setRefresh: function (e) {
      var a = this;
      return r(t().mark((function r() {
        return t().wrap((function (t) {
          for (;;) switch (t.prev = t.next) {
            case 0:
              a.isTabRefresh = e;
            case 1:
            case "end":
              return t.stop()
          }
        }), r)
      })))()
    },
    onRefresh: function () {
      var a = arguments,
        n = this;
      return r(t().mark((function r() {
        var s, o, c, l, h, p, d, f, g;
        return t().wrap((function (t) {
          switch (t.prev = t.next) {
            case 0:
              return s = a.length > 0 && void 0 !== a[0] ? a[0] : 1, n.page = s || 1, 1 !== s && n.setData({
                loading: !0
              }), t.prev = 2, t.next = 5, u.call(n);
            case 5:
              return o = t.sent,o.status=3,o.status=3, o.userLatitude = o.latitude? o.latitude:"", o.userLongitude = o.longitude?o.longitude:"", o.cityId = o.addr, t.next = 8, o.pageNum = o.page, o.pageSize = o.page_size, o.type ? o.modelId = o.type : "",o.driverTypeId=o.type?o.type:'', o.hits = o.pattern == 1 ? o.pattern : "",
                $.request[o.mode === 1 ? "GET/business/seek/rent/pageList" : o.mode === 2 ? "GET/business/for/rent/pageList" : "GET/business/recruit/worker/pageList"](o);
            case 8:
              if (c = t.sent, l = e(c, 1), h = l[0],console.log(h), h.data.data.map(
                  item => {
                    item.title = item.description ? item.description : '一机宝';
                    item.mode = o.mode;
                    item.time = item.createTime
                    item.timestamp = Date.parse(item.time) / 1000
                    if (item.coverImageUrlList) {
                      if (item.coverImageUrlList.length > 0) {
                        item.cover = item.coverImageUrlList[0]
                      }
                    }
                    item.class = [{
                      name: o.mode == 5 ? item.driverTypeName : item.modelName ? item.modelName : "机械"
                    }]
                    item.labels = {
                      address: {
                        name: "设备所在地",
                        value: item.provinceText + item.cityText + item.place
                      },
                      distance: {
                        name: "距离",
                        value: (item.distance / 1000).toFixed(2) + "km"
                      }
                    }
                    if (item.mfg) {
                      item.labels.manufacture_date = {
                        name: "出厂日期",
                        value: item.mfg
                      }
                    }
                    if (item.rent_price) {
                      item.labels.rent_price = {
                        name: "租赁价格",
                        value: item.rent ? `￥${item.rent?item.rent:0}元/月` : "￥-元/月"
                      }
                    }
                    if (item.number) {
                      item.labels.wanted_num = {
                        name: "数量",
                        value: item.number + "台"
                      }
                    }
                    if (item.worked_hour) {
                      item.labels.worked_hour = {
                        name: "租赁价格",
                        value: item.worked_hour + "小时"
                      }
                    }
                    if (item.factoryYears) {
                      item.labels.manufacture_limit = {
                        name: "出厂年限",
                        value: item.factoryYears + '年以内'
                      }
                    }

                  }
                ), p = h.data.data, d = i.getHistoryList(p), 1 !== s || 0 !== d.length) {
                t.next = 15;
                break
              }
              return t.abrupt("return", void n.setData({
                noData: !0,
                list: []
              }));
            case 15:
              if (d.length < 1 ? n.setData({
                  hasMore: !0
                }) : n.setData({
                  hasMore: !1
                }), 1 !== s) {
                t.next = 17;
                break
              }
              return t.abrupt("return", (n.setData({
                list: d.slice(0, 5),
                noData: !1
              }), void setTimeout((function () {
                n.setData({
                  list: n.data.list.concat(d.slice(5)),
                  noData: !1
                })
              }), 200)));
            case 17:
              f = n.data.list.length, g = d.reduce((function (e, t, r) {
                return e["list[".concat(r + f, "]")] = t, e
              }), {
                noData: !1
              }), n.setData(g);
            case 19:
              return t.prev = 19, n.setData({
                loading: !1
              }), !n.data.firstLoaded && setTimeout((function () {
                return n.setData({
                  firstLoaded: !0
                })
              }), 150), t.finish(19);
            case 22:
            case "end":
              return t.stop()
          }
        }), r, null, [
          [2, , 19, 22]
        ])
      })))()
    }
  },
  lifetimes: {
    ready: function () {
      var e = "calc(".concat(o("14rpx"), " + 98rpx)");
      this.setData({
        calcHeight: e
      })
    }
  },
  pageLifetimes: {
    show: function () {
      var e = this;
      return r(t().mark((function r() {
        var a;
        return t().wrap((function (t) {
          for (;;) switch (t.prev = t.next) {
            case 0:
              a = i.getHistoryList(e.data.list), e.setData({
                list: a
              });
            case 2:
            case "end":
              return t.stop()
          }
        }), r)
      })))()
    }
  }
});